home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / v9n19.arc / WSMOOTH2.C < prev    next >
C/C++ Source or Header  |  1990-10-13  |  3KB  |  122 lines

  1. // wsmooth2.c RHS adjunct routines for WinSmooth
  2.  
  3. #include<windows.h>
  4. #include"wsmooth.h"
  5. #include"wsmooth2.h"
  6. #include<stdio.h>
  7. #include<stdarg.h>
  8. #include<malloc.h>
  9. #include<string.h>
  10. #include<stdlib.h>
  11. #include"filebuf.h"
  12.  
  13.  
  14. BOOL getoption(int *setting,char *str,char *op1,char *op2,char *op3,char *op4);
  15.  
  16. char mbuf[250];
  17.    // general message-to-user handler, like a printf for Windows
  18. void cdecl Message(HWND hwnd, char *format, ...)
  19.     {
  20.     va_list marker;
  21.  
  22.     va_start(marker, format);
  23.     vsprintf(mbuf,format, marker);
  24.     va_end(marker);
  25.  
  26.     MessageBox(hwnd,mbuf,"WinSmooth",MB_OK | MB_ICONEXCLAMATION);
  27.     }
  28.  
  29. extern SETTINGS settings;
  30. extern HWND WinSmooth;
  31. extern char windowname[128];
  32. extern char filename[128];
  33.  
  34.    // updates WinSmooth title bar
  35. void ChangeTitleBar(char *target)
  36.     {
  37.     char *p = strchr(windowname,' ');
  38.  
  39.     if(!p)
  40.         p = &windowname[strlen(windowname)];
  41.     *p = '\0';
  42.  
  43.     strcpy(filename,target);
  44.     strupr(filename);
  45.     strcat(windowname," ");
  46.     strcat(windowname,filename);
  47.     SetWindowText(WinSmooth,(LPSTR)windowname);
  48.     }
  49.  
  50.    // general function for initializing buffers and opening file
  51. int WSopenfile(char *target)
  52.     {
  53.     BOOL retval = TRUE;
  54.  
  55.     if(WinSmooth)
  56.         SendMessage(WinSmooth,WM_WSM_HOURGLASS_CURSOR,0,0L);
  57.     if(!filebuf_init())
  58.         {
  59.         SendMessage(WinSmooth,WM_WSM_NORMAL_CURSOR,0,0L);
  60.         Message(WinSmooth,"Fatal Error Initializing File Buffers!");
  61.         retval = FALSE;
  62.         }
  63.     else if(!filebuf_open(target,settings.stripbits))
  64.         retval = FALSE;
  65.  
  66.     if(WinSmooth)
  67.         {
  68.         ChangeTitleBar(target);
  69.         SendMessage(WinSmooth,WM_WSM_NORMAL_CURSOR,0,0L);
  70.         }
  71.     return retval;
  72.     }
  73.  
  74.    // reads filename and command-line options
  75. void process_cmdline(char *buffer)
  76.     {
  77.     char *p;
  78.     int setting;
  79.     
  80.     if(p = strchr(buffer,' '))                  // find space after filename
  81.         {
  82.         *p++ = '\0';
  83.         if(getoption(&setting,p,"/M","/m","-M","-m"))
  84.             if(setting >= MINMSECS && setting <= MAXMSECS)
  85.                 settings.Msecs = setting;
  86.             else
  87.                 Message(WinSmooth,"Value %u for /M option out-of-range: using default",
  88.                     setting);
  89.         if(getoption(&setting,p,"/P","/p","-P","-p"))
  90.             if(setting >= MINPIXELROWS && setting <= MAXPIXELROWS)
  91.                 settings.PixelRows = setting;
  92.             else
  93.                 Message(WinSmooth,"Value %u for /P option out-of-range: using default",
  94.                     setting);
  95.         setting = getoption(&settings.Msecs,p,"/W","/w","-W","-w");
  96.         }
  97.     }
  98.  
  99. BOOL getoption(int *setting,char *str,char *op1,char *op2,char *op3,char *op4)
  100.     {
  101.     char *ptr, *ptr2, temp[30];
  102.  
  103.     if((ptr = strstr(str,op1)) ||
  104.                 (ptr = strstr(str,op2)) ||
  105.                 (ptr = strstr(str,op3)) ||
  106.                 (ptr = strstr(str,op4)))
  107.         {
  108.         ptr += 2;
  109.         strcpy(temp,ptr);
  110.         ptr = temp;
  111.         if(ptr2 = strchr(ptr,' '))
  112.             *ptr2 = '\0';
  113.         *setting = atoi(ptr);
  114.         return TRUE;
  115.         }
  116.     return FALSE;
  117.     }
  118.  
  119.  
  120.  
  121. // end of wsmooth2.c
  122.